package controller

import (
	"github.com/gin-gonic/gin"
	"time"
	"webdemo/src/gin/base"
	"webdemo/src/gin/redisconfig"
)

func SetValue(ctx *gin.Context) {
	// RESTFUL -- GET
	key := ctx.Param("key")
	value := ctx.Param("value")
	redisClient := redisconfig.RedisClient
	redisClient.Set(key, value, time.Second*10)
	ctx.JSON(200, &base.Response{
		Success: true,
		Code:    200,
	})
}
func GetValue(ctx *gin.Context) {
	key := ctx.Param("key")
	redisClient := redisconfig.RedisClient
	value, err := redisClient.Get(key).Result()
	if err != nil {
		ctx.JSON(500, &base.Response{
			Success: false,
			Code:    500,
			Msg:     err.Error(),
		})
		return
	}

	ctx.JSON(200, &base.Response{
		Success: true,
		Code:    200,
		Data:    value,
	})
	return

}
